<?php 
    namespace Admin\Controller;

    class PowerController extends AdminController{
        private $Power = null; //数据库操作类

        //初始化操作
        public function _initialize()
        {
            parent::_initialize();
            $this->Power = D('power');
        }

        
        //显示权限用户列表
        public function index()
        {

            $list = $this->Power->select();
            $this->assign('list',$list);
            $this->display('Power/index');
        }


        //权限添加页面
        public function add()
        {
            $this->display('Power/add');
        }

        //执行权限添加处理
        public function addo()
        {
            if (IS_POST) {
                if (empty($_POST)) {
                    $this->error('不能什么都不填哟!!!!');
                }
                if(!$this->Power->create()){
                    $this->error($this->Power->getError());
                    exit;
                }

                if($this->Power->add() > 0){
                    $this->success("添加成功！",U('Power/index'));
                }else{
                    $this->error("添加失败！");
                }

            }else{
                $this->error('请求失败!!!');
            }
        }
        

        public function edit()
        {
            //查出数据
            $data = array('id'=>I('id'));
            // $id = $data['id'];
            $vo =$this->Power->where($data)->find();
            // dump($vo);
            // exit;
            //向模板分配数据
            $this->assign('vo',$vo);
            // //加载模板
            $this->assign('title','后台用户修改');
            $this->display('Power/edit');
        }


        public function editdo()
        {
            if (IS_POST) {
                if (empty($_POST)) {
                    $this->error('不能什么都不填哟!!!');
                }
                // 初始化
                if(!$this->Power->create()){
                    $this->error($this->Power->getError());
                    exit;
                }

                if ($this->Power->save() >=0) {
                    $this->success('修改成功',U('Power/index'));
                }else{
                    $this->error('修改失败');
                }





            }else{
                $this->error('请求失败!!');
            }
        }












    }
